package generic;
import org.junit.Test;

import java.util.Date;

public class GenericDemo {
    @Test
    public void test1(){
        Box<Date> dataInBox  = new Box<Date>(new Date());
        Box<String> stringInBox  = new Box<String>("hi jude");
//        System.out.println(dataInBox.getData());
//        System.out.println(dataInBox.getData());
        System.out.println(dataInBox);
        System.out.println(stringInBox);
        System.out.println(dataInBox.getClass());
        System.out.println(stringInBox.getClass());
    }

    @Test
    public void test2(){
        Box<Integer> box1 = new Box<>(111);
        Box<Number> box2 = new Box<>(222);
        Box<String> box3 = new Box<>("this is a string");

        getData1(box1);
        getData1(box2);
        getData1(box3);

        getData2(box1);
        getData2(box2);
//        getData2(box3);

        getData3(box1);
        getData3(box2);
//        getData3(box3);


    }

    public void getData1(Box<?> box){
        System.out.println(box.getData());
    }

    public void getData2(Box<? extends Number > box){
        System.out.println(box.getData());
    }

    public void getData3(Box<? super Integer > box){
        System.out.println(box.getData());
    }

    class Box<T>{
        private T data;

        public Box(T data){
            this.data = data;
        }

        public T getData() {
            return data;
        }
    }

    @Test
    public void test3(){
        String gf = gf(1,new String("2122"));
        System.out.println(gf);
    }

    public <T,E> E gf(T t,E e){
        return e;
    }


}
